/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.fee.core.service.processor.rule;

import cn.hutool.core.util.ObjectUtil;
import info.peigen.hotpot.business.fee.core.domain.FeeRule;
import info.peigen.hotpot.business.fee.core.domain.action.FeeConverter;
import info.peigen.hotpot.business.fee.core.service.processor.base.AbstractFeeServiceProcessor;
import info.peigen.hotpot.business.fee.facade.command.result.FeeRuleCreateResult;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(FeeRuleCreateProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/6/1
 */
@Component
public class FeeRuleCreateResultProcessor extends AbstractFeeServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 91;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        FeeRule domain = (FeeRule) serviceContext.getDomain();
        if (ObjectUtil.isNotNull(domain)) {
            FeeRuleCreateResult result = (FeeRuleCreateResult) serviceContext.getResult();
            result.fromSuccess(FeeConverter.convertFeeRuleInfo(domain));
            result.setRuleId(domain.getRuleId())
                    .setSuccessNotFee();
        }
    }
}
